package controller.admin;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.validation.BindException;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.AbstractCommandController;

import Bean.highlightBean;
import dao.highlightDao;

public class DBinsertController extends AbstractCommandController {

	private highlightDao hldao;

	public void setHldao(highlightDao hldao) {
		this.hldao = hldao;
	}

	@Override
	protected ModelAndView handle(HttpServletRequest request,
			HttpServletResponse response, Object obj, BindException error)
			throws Exception {

		highlightBean bean = (highlightBean) obj;
		ModelAndView mav = new ModelAndView();

		if(bean.getNo2() == null || bean.getNo2().equals(""))
			bean.setNo2("0");
		if(bean.getO3() == null || bean.getO3().trim().equals(""))
			bean.setO3("0");
		if(bean.getCo() == null || bean.getCo().trim().equals(""))
			bean.setCo("0");
		if(bean.getSo2() == null || bean.getSo2().trim().equals(""))
			bean.setSo2("0");
		if(bean.getPm10() == null || bean.getPm10().trim().equals(""))
			bean.setPm10("0");
		if(bean.getPm25() == null || bean.getPm25().trim().equals(""))
			bean.setPm25("0");

		hldao.AdminDBinsert(bean);

		mav.setViewName("DBpage");

		return mav;
	}
}
